package com.portal.mq.controller;

import com.portal.common.security.annotation.InnerAuth;
import com.portal.mq.service.RabbitMqService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/rabbitmq")
public class MQController {
    @Resource
    private RabbitMqService rabbitMqService;

    @InnerAuth
    @PostMapping("/send")
    public void sendMessage(@RequestParam String exchange,
                            @RequestParam String routingKey,
                            @RequestParam String queue,
                            @RequestParam Object message) {
        // 声明队列和交换机
        rabbitMqService.declareQueueAndExchange(queue, exchange);
        // 发送消息
        rabbitMqService.sendMessage(exchange, routingKey, message);
    }
}
